package com.ijunfu.spring._import._04_import_registrar.registrar;

import com.ijunfu.spring._import._04_import_registrar.service.UserService;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 *
 * @Title  : 
 * @Author : ijunfu <ijunfu@163.com>
 * @Date   : 2023/11/7 14:56
 * @Version: 1.0
 * @Motto  : 世界很大 世界很小
 *
 */
public class MyImportRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();

        AbstractBeanDefinition userBeanDefinition = builder.getBeanDefinition();
        userBeanDefinition.setBeanClass(UserService.class);
        registry.registerBeanDefinition("userService", userBeanDefinition);

    }
}
